package com.wutianyi.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

/**
 * @author wutianyi 默认的处理
 */
public class DefaultController extends AbstractController {

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {

		ModelAndView view = new ModelAndView();

		String uri = request.getRequestURI();

		int index = uri.indexOf('.');
		if (index != -1) {
			uri = uri.substring(0, index);
		}

		String contextPath = request.getContextPath();
		if (uri.startsWith(contextPath)) {
			uri = uri.substring(contextPath.length());
		}

		System.out.println(uri);
		view.setViewName("/" + uri);

		return view;
	}
}
